<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/dailybill/css/lecturer.css"/>
    <script type="text/javascript" src="/dailybill//js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/dailybill/js/mobileSelect.js"></script>
	 <link rel="stylesheet" type="text/css" href="/dailybill/css/mobileSelect.css"/>
    <script type="text/javascript" src="/dailybill/js/rem.js" ></script>
        <script type="text/javascript" src="/plan/js/layer.js" ></script>
    <script type="text/javascript" src="/dailybill/js/mescroll.min.js" ></script>
	<link rel="stylesheet" type="text/css" href="/dailybill/css/mescroll.min.css"/>
      <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
	<title>派讲师</title>
</head>
<body>
	<div class="top">
		<div class="top_center">
			<span class="top_left_con1">
				<div id="trigger4" class="trigger4" style="display: inline-block;font-size: 0.28rem;color: #555;">
					开会周次
				</div>
			</span>
			<img class="top_left_xia1" src="/dailybill/img/jtxia.png" />
		</div>
	</div>
	<div id="mescroll" class="mescroll">
		<ul class="list" id="dataList">
	    </ul>
	</div>
  <input type="hidden" id="time">
    <input type="hidden" id="year">
	<a href="javascript:;" id="send"><div class="submit">发送通知</div></a>
</body>
<script>
 wx.config({$json});
 wx.checkJsApi({
    jsApiList: ['selectEnterpriseContact','openEnterpriseChat'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
    success: function(res) {
        // 以键值对的形式返回，可用的api值true，不可用为false
        // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
    }
});
wx.ready(function(){
  $(document).on('click', ".num_right", function () {
     var id = $(this).attr("attrid");
     var lectuerid = $(this).attr("lectuerid");
       wx.invoke("selectEnterpriseContact", {
                "fromDepartmentId": 58,// 必填，-1表示打开的通讯录从自己所在部门开始展示, 0表示从最上层开始
                "mode": "single",// 必填，选择模式，single表示单选，multi表示多选
                "type": ["user"],// 必填，选择限制类型，指定department、user中的一个或者多个
                "selectedDepartmentIds": [],// 非必填，已选部门ID列表。用于多次选人时可重入
                "selectedUserIds": [lectuerid]// 非必填，已选用户ID列表。用于多次选人时可重入
            },function(res){
                if (res.err_msg == "selectEnterpriseContact:ok")
                {
                    if(typeof res.result == 'string')
                    {
                        alert('不兼容');
                        res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容，需要开发者额外判断result类型以保证在各个终端的兼容性
                    }
                    var selectedDepartmentList = res.result.departmentList;// 已选的部门列表
                    for (var i = 0; i < selectedDepartmentList.length; i++)
                    {
                        var department = selectedDepartmentList[i];
                        var departmentId = department.id;// 已选的单个部门ID
                        var departemntName = department.name;// 已选的单个部门名称
                    }
                    var selectedUserList = res.result.userList; // 已选的成员列表
                    for (var i = 0; i < selectedUserList.length; i++)
                    {
                        var user = selectedUserList[i];
                        var userId = user.id; // 已选的单个成员ID
                        var userName = user.name;// 已选的单个成员名称
                        var userAvatar= user.avatar;// 已选的单个成员头像
                    }
                    $.ajax({
                      type: 'post',
                      url:"/index/lecturers/edit/ids/"+id,
                      data:{lecturer_id:userId},
                      dataType: "json",
                      success: function(data){
                        if(data.code){
                          $("#avatar_"+id).attr("src", userAvatar);
                          $("#lecturer_"+id).attr("lectuerid", userId);
                           layer.open({
                            content:'操作成功' ,
                            skin: 'msg',
                            time: 2 //2秒后自动关闭
                          });
                          }else{
                           layer.open({
                            content:'操作失败,请刷新重试' ,
                            skin: 'msg',
                            time: 2 //2秒后自动关闭
                          });
                          }
                       }
                     });

                }
            }
        );
  });
});
$('#send').click(function(){
    var time = $('#time').val();
    var year = $('#year').val();
    var index = layer.open({type: 2});
    $.ajax({
      type: 'post',
      url:"/index/lecturers/send",
      data:{time:time,year:year},
      dataType: "json",
      success: function(data){
        if(data.code){
             layer.open({
            content:'操作成功' ,
            skin: 'msg',
            time: 2 //2秒后自动关闭
          });
          }else{
              layer.open({
            content:data.msg ,
            skin: 'msg',
            time: 2 //2秒后自动关闭
          });
          }
          layer.close(index);
    
       }
     });
   });
var mescroll = new MeScroll("mescroll", {

    up: {
        callback: getListData, //上拉加载的回调
        page: {
      num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
      size: 10 //每页数据条数,默认10
    },
        isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
    noMoreSize: 1, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
    empty: {
      icon: "/plan/img/wu.png", //图标,默认null
      tip: " ", //提示
    },
    clearEmptyId: "dataList", //相当于同时设置了clearId和empty.warpId; 简化写法;默认null; 注意vue中不能配置此项
    toTop:{ //配置回到顶部按钮
      src : "/plan/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
      //offset : 1000
    },
    htmlNodata: '<p class="upwarp-nodata">-- END --</p>',
    lazyLoad: {
          use: true // 是否开启懒加载,默认false
        }
    }
});
/*初始化菜单*/
var department=0;
$(".examine li").click(function(){
  var i=$(this).attr("i");
  if(department!=i) {
    //更改列表条件
    department=i;
    //重置列表数据
    mescroll.resetUpScroll();
    //隐藏回到顶部按钮
    mescroll.hideTopBtn();
  }
})
var time = '';
var year = '';

function getListDataFromNet(pageNum,pageSize,time,year,successCallback,errorCallback) {
  //console.log(pageSize);
    $.ajax({
      url: '/index/lecturers/lists_ajax?offset='+pageNum+'&limit='+pageSize+'&time='+time+'&year='+year,
      type: 'get',
      success: function (res) {
      //console.log(res);
        var list = res.rows;
      successCallback(list,res.total);
      },
       error: errorCallback
    })
  }
    /*设置列表数据*/
  function setListData(curPageData){
    var listDom=document.getElementById("dataList");
    for (var i = 0; i < curPageData.length; i++) {

      var value=curPageData[i];
       var html ='<div class="number">'+value.department_text;
       if(value.lecturer_id){
          html +='<span class="num_right" id="lecturer_'+value.id+'" attrid="'+value.id+'" lectuerid = "'+value.lecturer_id+'"><img src="'+value.lecturer_avatar_text+'" id="avatar_'+value.id+'"/></span>';
        }else{
            html +='<span class="num_right" id="lecturer_'+value.id+'" attrid="'+value.id+'" ><img src="'+value.lecturer_avatar_text+'" id="avatar_'+value.id+'"/></span>';
        }
          html +='<p class="taskinfo info">开会场次：'+value.season+'场  开会地点：'+value.address+'</p>';
          html +='</div>';
          html +='<div class="date">';
          html +='<span class="date_left">'+value.desc+'</span></div>';

      var liDom=document.createElement("li");
      liDom.innerHTML=html;
      listDom.appendChild(liDom);
    }
  }
  var arr = [];
  var DefaultsDate = {$DefaultsDate};
  var DefaultsDateW = {$DefaultsDateW};
  var years = {$DefaultsDate};
  var week_text = {$DefaultsDateW};
  var department = 0;
    $.ajax({
    url: '/api/ajax/year_week',
    type: 'post',
    async: false,
    data:{type:1,year:years,week_text:week_text,department:department},
    success: function (year) {
         arr = year.data.data;
         DefaultsDate = year.data.year_more;
         DefaultsDateW = year.data.week_more;
    }
  });
    var mobileSelect4 = new MobileSelect({
      trigger: '#trigger4',
      title: '周次选择',
      wheels: [{data:arr}],
      position:[DefaultsDate,DefaultsDateW],
     transitionEnd:function(indexArr, data){
            
     },
     callback:function(indexArr, data){
      if(data[0].value != 0){
        var strs = data[1].name.split(",");
         $('#trigger4').text('开会周次');
          time = data[1].value;
        }else{
          time = 0;
        }
        year = data[0].value;
      //重置列表数据
      mescroll.resetUpScroll();
      //隐藏回到顶部按钮
      mescroll.hideTopBtn();
     }
  });

  /*联网加载列表数据  page = {num:1, size:10}; num:当前页 从1开始, size:每页数据条数 */
function getListData(page){
  var pageNum = page.num - 1;
  if(!time && !year && arr.length){
     time = arr[DefaultsDate]['childs'][DefaultsDateW]['value'];
     year = arr[DefaultsDate]['value'];
   
  }
  $('#time').val(time);
  $('#year').val(year);
  //联网加载数据
  getListDataFromNet(pageNum, page.size,time,year, function(curPageData,totalSize){
    //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
    //mescroll会根据传的参数,自动判断列表如果无任何数据,则提示空;列表无下一页数据,则提示无更多数据;
    console.log("page.num="+pageNum+", page.size="+page.size+", curPageData.length="+curPageData.length);
    //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
    mescroll.endBySize(curPageData.length, totalSize); //必传参数(当前页的数据个数, 总数据量)
    //提示:curPageData.length必传的原因:
    // 1.判断是否有下一页的首要依据: 当传的值小于page.size时,则一定会认为无更多数据.
    // 2.比传入的totalPage, totalSize, hasNext具有更高的判断优先级
    // 3.使配置的noMoreSize生效
    //设置列表数据
    setListData(curPageData);
  }, function(){
    //联网失败的回调,隐藏下拉刷新和上拉加载的状态;
        mescroll.endErr();
  });
}

</script>
</html>
